package Thread.Test.Test1;

public class RunThread implements Runnable {

    public static int ticket = 1000;
    public static Object obj = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (ticket <= 0) {
                    //没票,结束循环
                    break;
                } else {
                    //有票
                    ticket--;
                    System.out.println(Thread.currentThread().getName() + "窗口还剩" + ticket + "张票");
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}
